package com.gujia.concurrency.example.atomic;

import com.gujia.concurrency.annoations.ThreadSafe;
import jdk.nashorn.internal.objects.annotations.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReference;

@Slf4j
@ThreadSafe
public class AtomicExample5 {
    
    public static AtomicIntegerFieldUpdater<AtomicExample5> updater = AtomicIntegerFieldUpdater.newUpdater(AtomicExample5.class,"count");


    private  volatile  int count = 100;

    public int getCount() {
        return count;
    }

    public static void main(String[] args) throws Exception {

         AtomicExample5 atomicExample5 = new AtomicExample5();

        if(updater.compareAndSet(atomicExample5,100,120)){
            System.out.println("count:"+atomicExample5.getCount());
        }

        if(updater.compareAndSet(atomicExample5,100,150)){
            System.out.println("count2:"+atomicExample5.getCount());
        }


    }


}
